/**
 * 至少一个属性
 */
export type OneProp<T> = {
  [P in keyof T]-?: Record<P, T[P]>;
}[keyof T];

// 请求响应参数（不包含data）
export interface Result {
  code: string;
  msg: string;
}

// 请求响应参数（包含data）
export interface ResultData<T = any> extends Result {
  [x: string]: any;
  result?: T;
}

// 分页响应参数
export interface ResPage<T> {
  list: T[];
  pageNum: number;
  perPageNum: number;
  total: number;
}

// 分页请求参数
export interface ReqPage {
  pageNum: number;
  perPageNum: number;
}

// 文件上传模块
export namespace Upload {
  export interface ResFileUrl {
    fileUrl: string;
  }
}

// 登录模块
export namespace Login {
  export interface ReqLoginForm {
    optcode: string;
    password: string;
    captcha: string;
  }
  export type ResLogin = ResultData;
  export interface ModifyPsd {
    oldPassword: string;
    newPassword: string;
    captcha: string;
  }
}

// 用户管理模块
export namespace User {
  export interface ReqUserParams extends ReqPage {
    clause: string;
    orgUnitIDs: string[];
  }
  export interface ResUserList {
    [key: string]: any;
  }
  export interface ResDoorRightsList {
    [key: string]: any;
  }

  export type ResRoleSelList = RoleList;
  export interface RoleList {
    roleId: string;
    roleName: string;
    note?: string;
  }
}
//角色管理模块
export namespace Role {
  export interface ReqRoleParams extends ReqPage {
    roleName: string;
    description: string;
    status: number;
    permissionTree: ResPermission[];
  }
  export interface ResRoleList {
    roleId: string;
    roleName: string;
    description: string;
    users: number;
    status: number;
    createTime: Date;
    isDefault: number;
  }
  export interface ResPermission {
    [key: string]: any;
  }
}
//柜体管理模块
export namespace Cabinet {
  export interface ReqCabinetInfoParams extends ReqPage {
    deviceName: string;
    deviceNo: string;
    deviceType: string;
    deviceFactory: string;
  }
  export interface ResCabinetInfoList {
    deviceId: string;
    deviceName: string;
    deviceNo: string;
    deviceType: string;
    deviceIp: string;
    devicePort: number;
    deviceAddress: number;
    deviceFactory: string;
    createTime: Date;
    updateTime: Date;
    updateUserName: string;
    connectStatus: number;
    facesNums?: number;
  }
}
//工位管理模块
export namespace Station {
  export interface ReqStationInfoParams extends ReqPage {
    deviceId: string;
    stationName: string;
    stationType: string;
  }
  export interface ResStationInfoList {
    stationId: string;
    deviceId: number;
    deviceName: string;
    stationName: string;
    stationNo: number;
    stationType: string;
    stationAddress: string;
    powerAddress: number;
    createTime: Date;
    updateTime: Date;
    updateUserName: string;
    deviceFaces?: string;
    baudrate?: string;
  }
}

// 终端管理
export namespace Terminal {
  export interface ReqTerminalInfoParams extends ReqPage {
    deviceId: string;
    termName: string;
    termType: string;
  }
  export interface ResTerminalInfoList {
    stationId: string;
    deviceId: string;
    deviceName: string;
    stationName: string;
    termId: string;
    termName: string;
    termNo: string;
    termType: string;
    termAddress: string;
    linestyle: string;
    protocol: string;
    commType: string;
    termIp: string;
    termPort: string;
    baudrate: string;
    createTime: Date;
    updateTime: Date;
    connectStatus: number;
    updateUserName: string;
  }
}

//电表管理
export namespace E_Meter {
  export interface ReqE_MeterInfoParams extends ReqPage {
    deviceId: string;
    meterType: string;
    linestyle: string;
    protocol: string;
  }
  export interface ResE_MeterInfoList {
    stationId: string;
    deviceId: string;
    termId: string;
    meterId: string;
    meterNo: string;
    meterType: string;
    meterAddress: string;
    linestyle: string;
    protocol: string;
    baudrate: string;
    ct: string;
    commPort: string;
    messureNo: string;
    createTime: Date;
    updateTime: Date;
    updateUserName: string;
  }
}
// 控制命令
export namespace CommandTree {
  export interface ReqCommandTreeParams {
    objectStyle: number;
  }
  export interface ResCommandTree {
    dataTree: CommandTreeList[];
  }
  interface CommandTreeList {
    commandId: string;
    dataName: string;
    children?: CommandTreeChild[];
  }
  interface CommandTreeChild extends CommandTreeList {
    CommandTreeList: any[];
  }
}
// 控制表单
export namespace Control {
  export type ReqControlParams<T = DeviceKey> = {
    commandId: string;
    dataItemList?: DeviceItem[];
  } & T &
    OneProp<T>;
  export interface ResControlMap extends DeviceItem {
    dataItemMap: DeviceItem[];
  }
  interface DeviceKey {
    deviceId?: string;
    stationId?: string;
    termId?: string;
    meterId?: string;
  }
  interface DeviceItem {
    itemId: string;
    itemValue: string;
    itemName?: string;
  }
}
// 设备树
export namespace ObjectTree {
  export interface ResObjectTree {
    dataList: ObjectTreeItem[];
  }
  interface ObjectTreeItem {
    id: string;
    parentId: string;
    name: string;
    tag: string;
    children: ObjectTreeItem[];
  }

  // 题库管理
  export namespace TrainQuestion {
    export interface ReqTrainQuestionParams extends ReqPage {
      objectStyle: string;
    }
    export interface ResTrainQuestionList {
      questionId: number;
      objectStyle: number;
      commandId: string;
      dataName: string;
      createTime: Date;
      majorType: number;
      updateTime: Date;
      updateUserId: string;
      dataItemList: dataItemList[];
    }
    export interface dataItemList {
      itemId: string;
      itemName: string;
      commandId: string;
    }
  }

  // 培训计划管理
  export namespace TrainPlan {
    export type ReqTrainPlanParams = ReqPage;
    export interface ResTrainPlanList {
      questionId: any;
      dataName: any;
      planId: number;
      planName: string;
      questionNums: string;
      deviceList: deviceList[];
    }
    export interface deviceList {
      deviceId: string;
      deviceName: string;
    }

    export interface ReqStationNoParams {
      deviceList: {
        deviceId: string;
      }[];
    }
    export interface ResStationNoList {
      dataList: {
        stationNo: string;
      }[];
    }
    export interface ResSendTrainPlanRecord {
      controlId: number;
      sendStatus: number;
      totalNums: number;
      success: number;
      sendTime: Date;
      completeTime: Date;
      sendUserName: string;
    }
  }

  // 试卷管理
  export namespace TestPaper {
    export type ReqTestPaperParams = ReqPage;
    export interface ResTestPaperList {
      examId: number;
      examName: string;
      questionNums: number;
      totalScore: number;
      deviceList: deviceList[];
    }
    export interface ReqStationNoParams {
      deviceList: {
        deviceId: string;
      }[];
    }
    export interface ResStationNoList {
      dataList: {
        stationNo: string;
      }[];
    }
    export interface deviceList {
      deviceId: string;
      deviceName: string;
    }
  }

  // 考试管理
  export namespace Exam {
    export type ReqExamInfoParams = ReqPage;
    export interface ResExamInfoList {
      times: number;
      testId: number;
      testName: string;
      examId: number;
      examName: string;
      roomName: string;
      startTime: Date;
      endTime: Date;
      status: number;
      createTime: Date;
      connectStatus: number;
      controlList: controlList[];
    }
    export interface ReqExamSelfParams extends ReqPage {
      testName: string;
    }
    export interface ReqTestSubmitParams {
      controlId: number;
      questionList: {
        eqId: number;
      }[];
      dataList: {
        itemId: number;
        itemValue: string;
      }[];
    }
    export interface ResExamSelfList {
      controlId: number;
      testId: number;
      testName: string;
      roomName: string;
      startTime: Date;
      endTime: Date;
      status: number;
      totalScore: number;
      winScore: number;
      times: number;
      teacherId: string;
      teacherName: string;
      studentId: string;
      studentName: string;
    }
    export interface ResTestInfo {
      testInfo: any;
      questionList: QuestionList[];
    }
    interface QuestionList {
      eqId: number;
      objectStyle: number;
      commandId: string;
      dataName: string;
      stationNo: string;
      score: number;
      dataList: dataList[];
      answerIsRight?: number;
    }
    interface controlList {
      [x: string]: any;
      deviceId: number;
      teacherId: number;
    }
    interface dataList {
      itemId: number;
      itemName: string;
      itemType: number;
      selectList?: {
        lable: string;
        value: string;
      }[];
      isSelected?: boolean;
    }
  }

  export namespace NewEnergy {
    export type ReqCabinetInfoParams<T = Cabinet.ReqCabinetInfoParams> = T & OneProp<T>;
    export type ResCabinetInfoList<T = Cabinet.ResCabinetInfoList> = T & {
      facesNums: number;
      faceList: { faceNo: string; faceIp: string | number; facePort: string | number }[];
    } & OneProp<T>;
    export interface ReqStationInfoParams extends ReqPage {
      deviceId: string;
      faceNo: string;
    }
    export type ResStationInfoList<T = Station.ResStationInfoList> = T & {
      faceNo: number;
    } & OneProp<T>;
    export interface ReqTerminalInfoParams extends ReqPage {
      deviceId: string;
      termName: string;
      termType: string;
      faceNo: string;
    }
    export type ResTerminalInfoList<T = Terminal.ResTerminalInfoList> = T & {
      faceNo: number;
    } & OneProp<T>;
    export interface ReqE_MeterInfoParams extends ReqPage {
      deviceId: string;
      meterType: string;
      linestyle: string;
      protocol: string;
      faceNo: string;
    }
    export type ResE_MeterInfoList<T = E_Meter.ResE_MeterInfoList> = T & {
      faceNo: number;
    } & OneProp<T>;

    export interface NewEnergyConfig {
      baudrate: string;
      saveTime: number;
      operateTime: number;
      studentRole: number;
      wiringDiagram: number;
    }

    export interface NewEnergyOperateSelect {
      faceNo: string;
      operateType: string;
      voltage: string;
      deviceId: string;
    }

    export interface NewEnergyWireCheck {
      faceNo: string;
      deviceId: string;
    }

    export interface NewEnergyUpPower {
      faceNo: string;
      deviceId: string;
      upType: number;
    }

    export interface NewEnergyDownPower {
      faceNo: string;
      deviceId: string;
      downType: number;
    }

    export type NewEnergyRestDevice = NewEnergyWireCheck;
    export type NewEnergyCheckStatus = NewEnergyWireCheck;
    export type NewEnergyWireCheckResult = NewEnergyWireCheck;

    export interface ReqWirePhotoParams extends ReqPage {
      photoId: string;
    }
    export interface ResWirePhotoList {
      photoId: number;
      photoRemark: string;
      createTime: Date;
      photoContent?: string;
      photoSuffix?: string;
    }

    export interface ReqWireCheckLogParams extends ReqPage {
      userId: string;
      deviceId: string;
      faceNo: string;
    }
  }
}

export namespace CardIssuingCenter {
  export interface ReqEmployeeInfoParams extends ReqPage {
    clause: string;
    orgUnitIDs: string[];
  }
  export interface ResEmployeeInfoList {
    [key: string]: any;
  }
  export interface ResCardTypeList {
    [key: string]: any;
  }
}
